package com.exrobot.module.rbt.enums;

import com.exrobot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum MqttTopicSubEnum implements ArrayValuable<String> {
    // ========== 机器人日志类型 ==========
    UVLAMP_STATUS("/v1/devices/uvlamp-status", "uvlamp-status"),
    PREPARE_FOOD("/v1/devices/prepare-food", "prepare-food"),
    TASK_SITE("/v1/devices/task-site", "task-site"),
    CHARGE_TASK("/v1/devices/vehicle-charge-task", "vehicle-charge-task"),
    OPERATION("/v1/devices/vehicle-operation", "vehicle-operation"),
    LOG_UPLOAD("/v1/devices/log-upload", "log-upload"),
    DELIVERY_FOOD("/v1/devices/delivery-food","delivery-food"),
    ORDER_CREATE("/v1/cloud/order-create","order-create"),
    ;
    /**
     * 类型值
     */
    private final String typeVal;
    /**
     * 类型名
     */
    private final String typeName;

    public static final String[] ARRAYS = Arrays.stream(values()).map(MqttTopicSubEnum::getTypeVal).toArray(String[]::new);

    public static MqttTopicSubEnum validateTypeVal(String typeVal) {
        for (MqttTopicSubEnum typeEnum : MqttTopicSubEnum.values()) {
            if (typeEnum.getTypeVal().equals(typeVal)) {
                return typeEnum;
            }
        }
        throw new IllegalArgumentException("非法类型： " + typeVal);
    }

    public static MqttTopicSubEnum getMqttEnum(String typeVal) {
        for (MqttTopicSubEnum typeEnum : MqttTopicSubEnum.values()) {
            if (typeEnum.getTypeVal().equals(typeVal)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static String getVal(String typeName) {
        for (MqttTopicSubEnum typeEnum : MqttTopicSubEnum.values()) {
            if (typeEnum.getTypeName().equals(typeName)) {
                return typeEnum.typeVal;
            }
        }
        return "";
    }

    public static String getName(String typeVal) {
        for (MqttTopicSubEnum typeEnum : MqttTopicSubEnum.values()) {
            if (typeEnum.getTypeVal().equals(typeVal)) {
                return typeEnum.typeName;
            }
        }
        return "未知";
    }

    @Override
    public String[] array() {
        return ARRAYS;
    }
}
